package com.zenchn.dynamic;

import static com.zenchn.dynamic.TSysRoleDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.zenchn.model.TSysRole;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface TSysRoleDynamicMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    BasicColumn[] selectList = BasicColumn.columnList(roleId, createTime, roleName, roleSign, roleLevel, status, isDefault, memo);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<TSysRole> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<TSysRole> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("TSysRoleResult")
    Optional<TSysRole> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="TSysRoleResult", value = {
        @Result(column="role_id", property="roleId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="role_sign", property="roleSign", jdbcType=JdbcType.VARCHAR),
        @Result(column="role_level", property="roleLevel", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="is_default", property="isDefault", jdbcType=JdbcType.BIT),
        @Result(column="memo", property="memo", jdbcType=JdbcType.VARCHAR)
    })
    List<TSysRole> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int deleteByPrimaryKey(String roleId_) {
        return delete(c -> 
            c.where(roleId, isEqualTo(roleId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int insert(TSysRole record) {
        return MyBatis3Utils.insert(this::insert, record, TSysRole, c ->
            c.map(roleId).toProperty("roleId")
            .map(createTime).toProperty("createTime")
            .map(roleName).toProperty("roleName")
            .map(roleSign).toProperty("roleSign")
            .map(roleLevel).toProperty("roleLevel")
            .map(status).toProperty("status")
            .map(isDefault).toProperty("isDefault")
            .map(memo).toProperty("memo")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int insertMultiple(Collection<TSysRole> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, TSysRole, c ->
            c.map(roleId).toProperty("roleId")
            .map(createTime).toProperty("createTime")
            .map(roleName).toProperty("roleName")
            .map(roleSign).toProperty("roleSign")
            .map(roleLevel).toProperty("roleLevel")
            .map(status).toProperty("status")
            .map(isDefault).toProperty("isDefault")
            .map(memo).toProperty("memo")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int insertSelective(TSysRole record) {
        return MyBatis3Utils.insert(this::insert, record, TSysRole, c ->
            c.map(roleId).toPropertyWhenPresent("roleId", record::getRoleId)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
            .map(roleName).toPropertyWhenPresent("roleName", record::getRoleName)
            .map(roleSign).toPropertyWhenPresent("roleSign", record::getRoleSign)
            .map(roleLevel).toPropertyWhenPresent("roleLevel", record::getRoleLevel)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(isDefault).toPropertyWhenPresent("isDefault", record::getIsDefault)
            .map(memo).toPropertyWhenPresent("memo", record::getMemo)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default Optional<TSysRole> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default List<TSysRole> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default List<TSysRole> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default Optional<TSysRole> selectByPrimaryKey(String roleId_) {
        return selectOne(c ->
            c.where(roleId, isEqualTo(roleId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, TSysRole, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    static UpdateDSL<UpdateModel> updateAllColumns(TSysRole record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(roleId).equalTo(record::getRoleId)
                .set(createTime).equalTo(record::getCreateTime)
                .set(roleName).equalTo(record::getRoleName)
                .set(roleSign).equalTo(record::getRoleSign)
                .set(roleLevel).equalTo(record::getRoleLevel)
                .set(status).equalTo(record::getStatus)
                .set(isDefault).equalTo(record::getIsDefault)
                .set(memo).equalTo(record::getMemo);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(TSysRole record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(roleId).equalToWhenPresent(record::getRoleId)
                .set(createTime).equalToWhenPresent(record::getCreateTime)
                .set(roleName).equalToWhenPresent(record::getRoleName)
                .set(roleSign).equalToWhenPresent(record::getRoleSign)
                .set(roleLevel).equalToWhenPresent(record::getRoleLevel)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(isDefault).equalToWhenPresent(record::getIsDefault)
                .set(memo).equalToWhenPresent(record::getMemo);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int updateByPrimaryKey(TSysRole record) {
        return update(c ->
            c.set(createTime).equalTo(record::getCreateTime)
            .set(roleName).equalTo(record::getRoleName)
            .set(roleSign).equalTo(record::getRoleSign)
            .set(roleLevel).equalTo(record::getRoleLevel)
            .set(status).equalTo(record::getStatus)
            .set(isDefault).equalTo(record::getIsDefault)
            .set(memo).equalTo(record::getMemo)
            .where(roleId, isEqualTo(record::getRoleId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_role")
    default int updateByPrimaryKeySelective(TSysRole record) {
        return update(c ->
            c.set(createTime).equalToWhenPresent(record::getCreateTime)
            .set(roleName).equalToWhenPresent(record::getRoleName)
            .set(roleSign).equalToWhenPresent(record::getRoleSign)
            .set(roleLevel).equalToWhenPresent(record::getRoleLevel)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(isDefault).equalToWhenPresent(record::getIsDefault)
            .set(memo).equalToWhenPresent(record::getMemo)
            .where(roleId, isEqualTo(record::getRoleId))
        );
    }
}